from collections import defaultdict

class Solution:
    def validPath(self, n: int, edges: List[List[int]], source: int, destination: int) -> bool:
        reached = set()
        def valid_path(src):
            if src == destination:
                return True
            reached.add(src)
            for n in maps[src]:
                if n not in reached and valid_path(n):
                    return True
            return False

        maps = defaultdict(list)
        for a, b in edges:
            maps[a].append(b)
            maps[b].append(a)
        return valid_path(source)
